<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<div class="setp_main">
	<table class="table" cellpadding="0" cellspacing="0" style="width:100%;table-layout: fixed;">
		<tr class="title">
			<td width="285px"><span class="stress">*</span>&nbsp;<s:property value="#orgTxt"/>ORG：</td>
			<td width="155px">&nbsp;</td>
			<td><span class="stress">*</span>&nbsp;<s:property value="#desTxt"/>DES：</td>
		</tr>
		<tr>
			<td>
            	<input type="text" id="expressExportCountry" name="expressExportCountry" value="<s:property value="work.expressExportCountry.fullname" />" autocomplete="off" tabindex="1"
            		onkeyup="seachDataByKeyword('searchCountryBykeyword.action?maxlen=2',this.value,'expressExportCountry','expressExportCountryId',0,235);" onblur="inputPoint()"/>
           		<input type="hidden" id="expressExportCountryId" name="work.expressExportCountry.id" value="<s:property value="work.expressExportCountry.id" />"/>
				<a id="orgInfoBtn" href="javascript:openPopDiv('orgInfo')" class="btn_info">&nbsp;</a>
			</td>
			<td align="center" id="transhipType1Td">
				<img src="${pageContext.request.contextPath}/cts/images/arrow_r.png"/>
			</td>
			<td>
            	<input type="text" id="expressImportCountry" name="expressImportCountry" value="<s:property value="work.expressImportCountry.fullname" />" autocomplete="off" tabindex="2"
            		onkeyup="seachDataByKeyword('searchCountryBykeyword.action?maxlen=2',this.value,'expressImportCountry','expressImportCountryId',0,235);" onblur="inputPoint()"/>
           		<input type="hidden" id="expressImportCountryId" name="work.expressImportCountry.id" value="<s:property value="work.expressImportCountry.id" />"/>
				<a id="desInfoBtn" href="javascript:openPopDiv('desInfo')" class="btn_info">&nbsp;</a>
			</td>
		</tr>
	</table>
	<table class="table" cellpadding="0" cellspacing="0" style="width: 100%; table-layout: fixed;">
		<tr class="title">
			<td width="230px;"><span class="stress">*</span>&nbsp;快递代理：</td>
			<td width="210px;"><span class="stress">*</span>&nbsp;快递公司</td>
			<td width="150px;">&nbsp;&nbsp;运单号：</td>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td>
				<input type="text" id="expressAgent1" name="expressAgent1" value="<s:property value="work.expressAgent1.nickname" />"
					onkeyup="seachDataByKeyword('searchEmployeeBykeyword.action?type=1',this.value,'expressAgent1','expressAgent1Id',0,150);" style="width:150px">
				<input type="hidden" id="expressAgent1Id" name="work.expressAgent1.id" value="<s:property value="work.expressAgent1.id" />">
				<a href="javascript:addEmployee('expressAgent1')" class="add_btn">&nbsp;</a>
			</td>
			<td style="white-space: nowrap">
				<s:select id="expressCarrier" name="work.expressCarrier.id" cssStyle="width:200px"
					list="#request.allCarrier" headerKey="0" headerValue="请选择" listKey="id" listValue="name" value="work.expressCarrier.id"></s:select>
				<font style="line-height: 45px; margin-left: -40px;">&nbsp;</font>
			</td>
			<td><input type="text" id="expressBookingNumber" name="work.expressBookingNumber" value="<s:property value="work.expressBookingNumber" />" style="width:130px"/></td>
			<td>&nbsp;</td>
		</tr>
		<tr class="title">
			<td colspan="4">&nbsp;&nbsp;运输要求：</td>
		</tr>
		<tr>
			<td colspan="4">
				<textarea id="expressDeliveryRequirements" name="work.expressDeliveryRequirements" class="input_xxl jNiceTextarea"><s:property value="work.expressDeliveryRequirements"/></textarea>
			</td>
		</tr>
		<tr class="title">
			<td colspan="4">&nbsp;&nbsp;运输反馈：</td>
		</tr>
		<tr>
			<td colspan="4">
				<textarea id="expressDeliveryFeedback" name="work.expressDeliveryFeedback" class="input_xxl jNiceTextarea"><s:property value="work.expressDeliveryFeedback"/></textarea>
			</td>
		</tr>
		<tr class="title">
			<td colspan="4">&nbsp;&nbsp;产品及服务：</td>
		</tr>
		<tr>
			<td colspan="4">
				<textarea id="expressProductService" name="work.expressProductService" class="input_xxl jNiceTextarea"><s:property value="work.expressProductService"/></textarea>
			</td>
		</tr>
		<tr class="title">
			<td colspan="4"><span class="stress">*</span>&nbsp;快递公司运输条款：</td>
		</tr>
		<tr>
			<td colspan="4">
				<s:select id="expressPayment2" name="work.expressPayment2" list="#{0:'寄件人',1:'收件人',2:'第三方'}"  
					headerKey="" headerValue="请选择付款方式" listKey="key" listValue="value" value="work.expressPayment2"></s:select>
			</td>
		</tr>
	</table>
</div>
<!-- 出口国信息 -->
<div id="orgInfo" class="popdiv_inner">
	<div class="popdiv_inner_outter"></div>
	<div class="popdiv_close" onclick="cancelPointInfo('orgInfo')"></div>
	<div class="popdiv_handle" style="font-size: 12px;" title="鼠标左键按住可拖动"><s:property value="#orgTxt"/>信息</div>
	<div class="popdiv_content" style="500px">
		<table style="width: 100%; font-size: 14px; border-bottom: 1px solid #d0d0d0;">
			<tr>
				<td align="right">收件地址：</td>
				<td>
					<input type="text" id="expressAddress1" name="work.expressAddress1" value="<s:property value="work.expressAddress1" />">
					<input type="hidden" id="expressAddress1Hide" value="<s:property value="work.expressAddress1" />" />
				</td>
			</tr>
			<tr>
				<td align="right"><span class="stress">*</span>ETD：</td>
				<td>
					<input type="text" id="expressETD" name="work.expressETD" class="calendar" onclick="WdatePicker()" value="<s:date name="work.expressETD" format="yyyy-MM-dd" />" >
					<input type="hidden" id="expressETDHide" value="<s:date name="work.expressETD" format="yyyy-MM-dd" />" />
				</td>
			</tr>
			<tr>
				<td align="right">收件时间：</td>
				<td>
					<input type="text" id="expressGetTime" name="work.expressGetTime" class="calendar" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" value="<s:date name="work.expressGetTime" format="yyyy-MM-dd HH:mm" />" >
					<input type="hidden" id="expressGetTimeHide" value="<s:date name="work.expressGetTime" format="yyyy-MM-dd HH:mm" />" />
				</td>
			</tr>
		</table>
		<div style="text-align: right; padding-top: 5px;">
			<input type="button" value="确认" onclick="savePointInfo('orgInfo');isInfo('expressETD')" style="width: auto;" />&nbsp;
			<input type="button" value="取消" onclick="hidePopDiv('orgInfo')" style="width: auto;" />
		</div>
	</div>
</div>

<!-- 进口国信息 -->
<div id="desInfo" class="popdiv_inner">
	<div class="popdiv_inner_outter"></div>
	<div class="popdiv_close" onclick="cancelPointInfo('desInfo')"></div>
	<div class="popdiv_handle" style="font-size: 12px;" title="鼠标左键按住可拖动"><s:property value="#desTxt"/>信息</div>
	<div class="popdiv_content" style="500px">
		<table style="width: 100%; font-size: 14px; border-bottom: 1px solid #d0d0d0;">
			<tr>
				<td align="right">送件地址：</td>
				<td>
					<input type="text" id="expressAddress2" name="work.expressAddress2" value="<s:property value="work.expressAddress2" />">
					<input type="hidden" id="expressAddress2Hide" value="<s:property value="work.expressAddress2" />" />
				</td>
			</tr>
			<tr>
				<td align="right"><span class="stress">*</span>ETA：</td>
				<td>
					<input type="text" id="expressETA" name="work.expressETA" class="calendar" onclick="WdatePicker()" value="<s:date name="work.expressETA" format="yyyy-MM-dd" />" >
					<input type="hidden" id="expressETAHide" value="<s:date name="work.expressETA" format="yyyy-MM-dd" />" />
				</td>
			</tr>
			<tr>
				<td align="right">送达时间：</td>
				<td>
					<input type="text" id="expressPutTime" name="work.expressPutTime" class="calendar" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" value="<s:date name="work.expressPutTime" format="yyyy-MM-dd HH:mm" />" >
					<input type="hidden" id="expressPutTimeHide" value="<s:date name="work.expressPutTime" format="yyyy-MM-dd HH:mm" />" />
				</td>
			</tr>
			<tr>
				<td align="right">送件代理：</td>
				<td>
					<input type="text" id="expressAgent2" name="expressAgent2" value="<s:property value="work.expressAgent2.nickname" />"
						onkeyup="seachDataByKeyword('searchEmployeeBykeyword.action?type=1',this.value,'expressAgent2','expressAgent2Id',0,150);" style="width:150px">
					<input type="hidden" id="expressAgent2Id" name="work.expressAgent2.id" value="<s:property value="work.expressAgent2.id" />">
					<input type="hidden" id="expressAgent2Hide" value="<s:property value="work.expressAgent2.nickname" />">
					<input type="hidden" id="expressAgent2IdHide" value="<s:property value="work.expressAgent2.id" />">
					<a href="javascript:addEmployee('expressAgent2')" class="add_btn">&nbsp;</a>
					<font style="line-height: 56px;">&nbsp;</font>
				</td>
			</tr>
		</table>
		<div style="text-align: right; padding-top: 5px;">
			<input type="button" value="确认" onclick="savePointInfo('desInfo');isInfo('expressETA')" style="width: auto;" />&nbsp;
			<input type="button" value="取消" onclick="hidePopDiv('desInfo')" style="width: auto;" />
		</div>
	</div>
</div>
<script>
$(function(){
	$('#expressAddress1,#expressAddress2').each(function(){$(this).pleaseInput()});
})

var preErrorId = [];
function validateForm(){
	var errorId = [];
	var errorMsg = '';
	var orgId = $('#expressExportCountryId').val();
	var desId = $('#expressImportCountryId').val();
	if(orgId == ''){
		errorId[errorId.length] = 'expressExportCountry';
		errorMsg += '<s:property value="#orgTxt" escape="false"/>不能为空\r\n';
	}
	if(desId == ''){
		errorId[errorId.length] = 'expressImportCountry';
		errorMsg += '<s:property value="#desTxt" escape="false"/>不能为空\r\n';
	}
	if(orgId != '' && desId != '' && orgId == desId){  //出发地和目的地
		errorId[errorId.length] = 'expressExportCountry';
		errorId[errorId.length] = 'expressImportCountry';
		errorMsg += '<s:property value="#orgTxt" escape="false"/>和<s:property value="#desTxt" escape="false"/>不能相同\r\n';
	}
	
	if($('#expressAgent1Id').val() == ''){
		errorId[errorId.length] = 'expressAgent1';
		errorMsg += '快递代理\r\n';
	}
	if($('#expressCarrier').val() == 0){
		errorId[errorId.length] = 'expressCarrier';
		errorMsg += '快递公司\r\n';
	}
	if($('#expressPayment2').val() == ''){
		errorId[errorId.length] = 'expressPayment2';
		errorMsg += '付款方式\r\n';
	}
	if(isInfo('expressETD')){ //出口国信息
		errorMsg += '<s:property value="#orgTxt" escape="false"/>信息\r\n';
	}
	if(isInfo('expressETA')){ //进口国信息
		errorMsg += '<s:property value="#desTxt" escape="false"/>信息\r\n';
	}
	if(typeof saveAllWorkItem == 'function'){
		errorMsg += saveAllWorkItem();
	}
	for(i=0; i<preErrorId.length; i++){
		normalCssJNice(preErrorId[i]);
	}
	if(errorMsg != ''){
		preErrorId = errorId;
		for(i=0; i< errorId.length; i++){
			errorCssJNice(errorId[i]);
		}
		alert(errorMsg);
		return;
	}
	if($('#expressAgent2Id').val() == ''){
		$('#expressAgent2Id').val(0);
	}
	$('#expressAddress1,#expressAddress2').each(function(){ this.isInput(true) });
	var params = $("#workForm").serialize();
	$('#expressAddress1,#expressAddress2').each(function(){ this.isInput(false) });
	$.post('cts/workStep3?save=true',params,function(result){
		if(result.trim() == 'null'){
			alert('订单不存在或已经被删除');
		}else if(result.trim() == 'status5'){
			alert('该订单已归档');
		}else if(result.trim() == 'ok'){
			nextStep();
		}else{
			alert('保存失败');
		}
	})
}

//是否正确输入地点信息
function isInfo(id){
	var infoBtn = {'expressETD':'orgInfoBtn','expressETA':'desInfoBtn'}
	var isInfo = false;
	if($('#'+id).val() == ''){
		errorCssJNice(id);
		$('#'+infoBtn[id])[0].className = 'btn_info_red';
		isInfo = true;
	}else{
		normalCssJNice(id);
		$('#'+infoBtn[id])[0].className = 'btn_info';
		isInfo = false;
	}
	return isInfo;
}

//保存地点信息
function savePointInfo(div){
	$('#'+div).find('input:text').each(function(){
		$('#'+this.id+'Hide').val(this.value);
	})
	hidePopDiv(div);
	$('#oceanVessel1,#voyNo1,#oceanVessel2,#voyNo2').each(function(){$(this).pleaseInput()});
}
//取消还原地点信息
function cancelPointInfo(div){
	$('#'+div).find('input:text').each(function(){
		this.value = $('#'+this.id+'Hide').val();
	})
	$('#oceanVessel1,#voyNo1,#oceanVessel2,#voyNo2').each(function(){$(this).pleaseInput()});
}
function inputPoint(){
	if(typeof changeTypeDetail == 'function') changeTypeDetail();
}
</script>